<?php
namespace app\serverarticle\service\article;

use \app\manage\service\ApiBase;
use think\Validate;

class ApiArticleClassify extends ApiBase
{
    protected $articleValidate = 'app\serverarticle\validate\ArticleClassify';
    protected $articleLogic    = '\app\serverarticle\logic\ArticleClassify';

    //添加app_key
    protected function _addAppKeyToRun($data = [], $path, $scene = '', $success = '1', $validate, $logic): array 
    {
        $data['key'] = config('yayi_admin_app_key');
        return $this->oneStepRun($data, $path, $scene, $success, $validate, $logic);
    }

    // 文章分类添加
    public function add()
    {
        $data = $this->receiveData(["name"=>" ", "key"=>" ", "pid"=>0, "order"=>0,"description"=>"","status"=>1,"add_user_id"=>" "]);
        return $this->oneStepRun($data, 'serverarticle/article/ApiArticleClassify/add', 'add', '1', $this->articleValidate, $this->articleLogic);
    }

    // 文章分类编辑
    public function edit(): array
    {
        $data = $this->issetReceiveData(["id"=>0, "key"=>" ", "name"=>" ", "pid"=>0, "order"=>0,"description"=>"","status"=>1,"add_user_id"=>" "]);
        return $this->oneStepRun($data, 'serverarticle/article/ApiArticleClassify/edit', 'edit', '1', $this->articleValidate, $this->articleLogic);
    }

    // 启用某个分类文章分类
    public function classifyEnable()
    {
        $data = $this->receiveData(['id'=>'', "key"=>" "]);
        return $this->oneStepRun($data, 'serverarticle/article/ApiArticleClassify/classifyEnable', 'enable', '1', $this->articleValidate, $this->articleLogic);
    }

    // 禁用某个分类文章分类
    public function classifyDisable()
    {
        $data = $this->receiveData(['id'=>'', "key"=>" "]);
        return $this->oneStepRun($data, 'serverarticle/article/ApiArticleClassify/classifyDisable', 'enable', '1', $this->articleValidate, $this->articleLogic);
    }

    // 删除某个分类文章分类
    public function classifyDelete()
    {
        $data = $this->receiveData(['id'=>'', "key"=>" "]);
        return $this->oneStepRun($data, 'serverarticle/article/ApiArticleClassify/classifyDelete', 'enable', '1', $this->articleValidate, $this->articleLogic);
    }

    // 全部文章分类列表获取
    public function classifyList()
    {
        return $this->oneStepRun([], 'serverarticle/article/ApiArticleClassify/classifyList', '', '1', $this->articleValidate, $this->articleLogic);
    }

    // 某一类文章分类列表获取
    public function classifySomeList()
    {
        $data = $this->receiveData(['pid'=>'', "key"=>" "]);
        return $this->oneStepRun($data, 'serverarticle/article/ApiArticleClassify/classifySomeList', 'pid', '1', $this->articleValidate, $this->articleLogic);
    }

    // 不同条件文章分类列表获取 (分页)
    public function classifyCondition()
    {
        $data = $this->receiveData(['keywords'=>'','page'=>1,'listRows'=>15]);
        return $this->oneStepRun($data, 'serverarticle/article/ApiArticleClassify/classifyCondition', '', '1', $this->articleValidate, $this->articleLogic);
    }
}
